import { ref } from 'vue'

import { getArticleCategoryList } from '@/api/article'

const categoryList = ref<ArticleCategoryInfoType[]>([])
const categoryCount = ref(0)
const isLoadingCategoryList = ref<boolean>(false)

function handleGetCategoryList(params: ArticleCategoryListParamsType) {
  isLoadingCategoryList.value = true

  return getArticleCategoryList(params)
    .then(res => {
      if (params.type === 1) {
        categoryList.value = res
      } else {
        categoryList.value = res.list
        categoryCount.value = res.count
      }
    })
    .finally(() => {
      isLoadingCategoryList.value = false
    })
}

export {
  categoryList,
  categoryCount,
  isLoadingCategoryList,
  handleGetCategoryList,
}
